using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DTO;
using Utility;
using BUS;
public partial class SanPham_quanlydonhang : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            loadData();
        }
    }
    protected void loadData()
    {
        try
        {
            Pager.PageSize = 10;
            int total = 0;
            Criteria c = new Criteria();
            c.add(Condition.AND, tbHoaDonColumns.khachhang, Condition.EQUAL, tbKhachHangBUS.GetByUsername(Session["username"].ToString()));
            tbHoaDonCollection dhCollection = tbHoaDonBUS.Get(c.Criter, Pager.CurrentIndex, Pager.PageSize,
              tbHoaDonColumns.mahd.ToString(), OrderDirection.ASC.ToString(), out total);
            Repeater1.DataSource = dhCollection;
            Repeater1.DataBind();
            Pager.ItemCount = total;
        }
        catch { }
        
    }

    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem ||
                 e.Item.ItemType == ListItemType.Item)
        {
            tbHoaDon donhang = (tbHoaDon)e.Item.DataItem;
            tbCTHoaDon ctdh = tbCTHoaDonBUS.GetByID(donhang.mahd);

            HyperLink hyp_madh = (HyperLink)e.Item.FindControl("hyp_madh");
            hyp_madh.Text = donhang.mahd.ToString();
            hyp_madh.NavigateUrl = "~/SanPham/quanlychitietdonhang.aspx?id=" + donhang.mahd.ToString();

            Literal lit_ngaydat = (Literal)e.Item.FindControl("lit_ngaydat");
            donhang.ngaydathang = DateTime.Parse(lit_ngaydat.Text);

            Literal lit_sodeal = (Literal)e.Item.FindControl("lit_sodeals");
            lit_sodeal.Text = ctdh.SoLuong.ToString();

            Literal cb_dagiao = (Literal)e.Item.FindControl("cb_dagiao");
            donhang.tinhtranggiaohang = int.Parse(cb_dagiao.Text);
        }
    }

}
